package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.NoticeListService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by chenzetong on 2017/4/15.
 */
@Controller
@RequestMapping("/rds_noticelist")
public class NoticeListController {
    @Resource
    private NoticeListService noticelistService;

    @RequestMapping(value = "/getNoticeListHome")
    @ResponseBody
    public JsonMsgDto getNoticeList(Integer userId) {
        JsonMsgDto dtResponseDto = new JsonMsgDto();
        try {
            dtResponseDto.setJsonData(noticelistService.getNoticeListHome(userId));
            dtResponseDto.setIsSuccess(true);
        } catch (Exception e) {
            dtResponseDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getNoticeByNotceId")
    @ResponseBody
    public JsonMsgDto getNoticeByNotceId(Integer noticeId) {
        JsonMsgDto dtResponseDto = new JsonMsgDto();
        try {
            dtResponseDto.setJsonData(noticelistService.getNoticeByNotceId(noticeId));
            dtResponseDto.setIsSuccess(true);
        } catch (Exception e) {
            dtResponseDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getNoticeList4DT")
    @ResponseBody
    public JsonMsgDto getNoticeList4DT(Integer start, Integer length, Integer userId, String search) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(noticelistService.getNoticeList4DT(start, length, userId, search));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteNoticeByUserNoticeId")
    @ResponseBody
    public JsonMsgDto deleteNoticeByUserNoticeId(String userNoticeIds) {
        JsonMsgDto dtResponseDto = new JsonMsgDto();
        try {
            dtResponseDto.setJsonData(noticelistService.deleteNoticeByUserNoticeId(userNoticeIds));
            dtResponseDto.setIsSuccess(true);
        } catch (Exception e) {
            dtResponseDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/updateIsRead")
    @ResponseBody
    public JsonMsgDto updateIsRead(Integer userNoticeId) {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            dto.setJsonData(noticelistService.updateIsRead(userNoticeId));
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }

}